import React, { Component } from 'react';
import {SingleInfo} from './common/Forminfo';
import {Link} from 'react-router';
import { InvoiceGet } from '../Redux/Actions/invoiceAction';
import { connect } from 'react-redux';
import {UctToLocaltime} from '../Config/Util';

class InvoiceDetail extends Component {

  componentWillMount(){
      this.props.dispatch(InvoiceGet(this.props.authReducer.user.data.token));
  }

  render() {
    const invoice = this.props.invoiceReducer.invoice.data==undefined?{remainInvoice:0,latestMakeInvoiceTimeOfThisMonth:null,latestMakeInvoiceTimeOfNextMonth:null}:this.props.invoiceReducer.invoice.data;
    if( invoice != undefined){
    return (
        <div className="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main">			
          <div className="row">
            <ol className="breadcrumb">
              <li><a href="#"><span className="glyphicon glyphicon-home"></span></a></li>
              <li>发票信息</li>
            </ol>
          </div>
          <div className="row">
            <div className="col-lg-12">
              <div className="panel panel-default">
                <div className="panel-heading">
                  发票信息
                  <Link className="pull-right btn btn-primary" style={{marginTop:"6px"}} to="/main/invoiceupdate">编辑</Link>
                </div>
                <div className="panel-body">
                  <div className="form-horizontal">
                    <SingleInfo label="本月剩余发票" info={invoice.remainInvoice}/>
                    <SingleInfo label="本月最迟开票日" info={UctToLocaltime(invoice.latestMakeInvoiceTimeOfThisMonth)}/>
                    <SingleInfo label="下月最早开票日" info={UctToLocaltime(invoice.latestMakeInvoiceTimeOfNextMonth)}/>
                  </div>
                </div>
              </div>
            </div>
          </div>	
        </div>
    )
    }else{
			return <div></div>
    }
  }
}
export default connect((state) => {
    const { authReducer,invoiceReducer } = state;
    return {
        authReducer,invoiceReducer
    }
})(InvoiceDetail); 